package easy.trace.agent.support;


import java.util.concurrent.atomic.AtomicLong;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class GenerateTraceId {
    private static Logger logger = LoggerFactory.getLogger(GenerateTraceId.class);
    private Long seed;
    private Long MAX_STEP = 16777215L;
    private AtomicLong plusId = new AtomicLong(0L);

    public GenerateTraceId(Long seed) {
        this.seed = seed;
    }

    public Long getTraceId() {
        return this.seed.longValue() << 40 | this.getPlusId();
    }

    private long getPlusId() {
        if (this.plusId.get() >= this.MAX_STEP.longValue()) {
            this.plusId.set(0L);
        }

        return this.plusId.incrementAndGet();
    }
}

